
import { IPSAppDEUIAction } from "@ibiz/dynamic-model-api";
import { MessageBox } from 'element-ui'; 
/**
 * 撤回插件类
 *
 * @export
 * @class Withdrawal
 */
export default class Withdrawal {

    /**
     * 模型数据
     * 
     * @memberof Withdrawal
     */
    private actionModel !: IPSAppDEUIAction;

    

    /**
     * 初始化 Withdrawal
     * 
     * @memberof Withdrawal
     */
    constructor(opts: any, context?: any) {
        this.actionModel = opts;
    }

    /**
     * 执行界面行为
     * 
     * @param args 
     * @param context 
     * @param params 
     * @param $event 
     * @param xData 
     * @param actionContext 
     * @param srfParentDeName 
     * 
     * @memberof Withdrawal
     */
    public async execute(args: any[], context: any = {}, params: any = {}, $event?: any, xData?: any, actionContext?: any, srfParentDeName?: string) {
             if (actionContext.appEntityService) {
      const tempContext = actionContext.context;
      const tempData = args[0];
      Object.assign(tempData, { taskId: actionContext.viewparams?.srftaskid });
      MessageBox.confirm('是否确认执行撤回操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        actionContext.appEntityService.WithDraw(tempContext, tempData).then((response: any) => {
          if (response && response.status === 200) {
            actionContext.closeView();
          } else {
            actionContext.closeView();
            actionContext.$throw(response, 'WithDraw');
          }

        }).catch((error: any) => {
          actionContext.$throw(error, 'WithDraw');
          actionContext.closeView();
        });
      }).catch(() => {
        actionContext.closeView();
      });
    }
    }

}

